﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ZGL.Api.Models.dto;
using ZGL.Api.Models.vo;
using ZGL.Api.Services.Role;
using ZGL.Api.Utils;

namespace ZGL.Api.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        public readonly IRoleService roleService;
        public RoleController(IRoleService RoleService)
        {
            this.roleService = RoleService;
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        [HttpPost]
        public IActionResult GetRoleList(RoleDto roleDto)
        {
            Dictionary<string, object> RoleList = roleService.getRoleList(roleDto);

            return new ObjectResult(new R(data: RoleList));
        }

        #region 角色新增
        /// <summary>
        /// 角色新增
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult addRole(RoleAddDto role)
        {
            roleService.addRole(role);
            return new ObjectResult(new R(data: null));
        }
        #endregion
        #region 修改角色
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult putRole(RolePutDto role)
        {
            roleService.putRole(role);
            return new ObjectResult(new R(data: null));
        }
        #endregion
        /// <summary>
        /// 获取角色详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult getRole(long id)
        {
            SysRoleVo Role = roleService.getRole(id);
            return new ObjectResult(new R(data: Role));
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        #region 删除角色
        [HttpDelete]
        public IActionResult delRole(long id)
        {
            roleService.delRole(id);
            return new ObjectResult(new R(data: null, code: 200, message: "请求成功"));
        }
        #endregion
    }
}
